# -*- coding:utf-8 -*-
'''
操作给定的二叉树，将其变换为源二叉树的镜像。
'''
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:
    # 返回镜像树的根节点
    def mir(self, root):
        if not root:
            return
        temp = root.left
        root.left = self.mir(root.right)
        root.right = self.mir(temp)
        return root

    def Mirror(self, root):
        # write code here
        if root is None:
            return
        if root.left is None and root.right is None:
            return root
        else:
            temp = root.left
            root.left = self.Mirror(root.right)
            root.right = self.Mirror(temp)
        return root